/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.beans.admin;

import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import manager.CountryManager;
import model.admin.Country;

/**
 *
 * @author Danh
 */
@ManagedBean
@RequestScoped
public class CountryBean {
    
    private int Country_Id;
    private String Country_Name;
    private boolean Country_status;
    
    public CountryBean() {
    }
    
    public void reset() {
        Country_Name = "";
        Country_status = false;
    }
    
    public CountryBean(int Country_Id, String Country_Name, boolean Country_status) {
        this.Country_Id = Country_Id;
        this.Country_Name = Country_Name;
        this.Country_status = Country_status;
    }
    
    public int getCountry_Id() {
        return Country_Id;
    }
    
    public void setCountry_Id(int Country_Id) {
        this.Country_Id = Country_Id;
    }
    
    public String getCountry_Name() {
        return Country_Name;
    }
    
    public void setCountry_Name(String Country_Name) {
        this.Country_Name = Country_Name;
    }
    
    public boolean getCountry_status() {
        return Country_status;
    }
    
    public void setCountry_status(boolean Country_status) {
        this.Country_status = Country_status;
    }
    
    public List<Country> loadCountry() {
        CountryManager mana = new CountryManager();
        return mana.getCountry();
    }

    public String editAction(int id, String name, boolean status) {
        this.Country_Id = id;
        this.Country_Name = name;
        this.Country_status = status;
        return "updateCountry.xhtml";
    }

    public void insertcountry() {
        Country c = new Country(this.Country_Name, this.Country_status);
        CountryManager mana = new CountryManager();
        boolean result = mana.insertCountry(c);
        if (result) {
            loadCountry();
        }
    }
    
    public String deleteCountry(int id) {
        CountryManager mana = new CountryManager();
        boolean deleteCountry = mana.deleteCountry(id);
        if (deleteCountry) {
            return "countryManager.xhtml?faces-redirect=true";
        }
        return "";
    }

    public String sua() {
        Country pr = new Country(Country_Id, Country_Name, Country_status);
        CountryManager mana = new CountryManager();
        mana.update(pr);
        return "countryManager.xhtml?faces-redirect=true";        
    }
}
